package cn.zwx.strategy.pattern.example.basic;

import org.springframework.stereotype.Service;

import java.util.Objects;

import static cn.zwx.strategy.pattern.example.basic.GrantTypeStrategy.GRANT_TYPE_STRATEGY_MAP;

/**
 * @projectName:strategy-pattern-example
 * @see:cn.zwx.strategy.pattern.example.basic
 * @author:zhangwenxue
 * @createTime:2022/2/11 10:18
 * @version:1.0
 */
@Service
public class BasicService {

    /**
     *  策略模式 虽然解决了if-else的问题 但是也暴露出
     *  对应的类增多的问题 虽然比switch case 易于维护但是不够优雅
     * @param resourceName xxx
     * @return java.lang.String
     * @author zhangwenxue
     * @createTime 2022/2/11 10:28
     **/
    public String getResult(String resourceName) {
        GrantTypeStrategy grantTypeStrategy = GRANT_TYPE_STRATEGY_MAP.get(resourceName);
        if (Objects.isNull(grantTypeStrategy)){
           return "查找不到该优惠券类型resourceType以及对应的派发方式";
        }
        return grantTypeStrategy.query();
    }
}
